package com.action.addrbook;

import com.common.DateProcess;
import com.db.addrbook.AddrBookDAO;
import com.db.addrbook.AddrBookVO;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

public class AddrInputAction implements ModelDriven<Object>, Preparable{
	private AddrBookVO abvo;
	private int byear;
	private int bmonth;
	private int bday;
	private AddrBookDAO abDAO;
	private DateProcess dateProc;
	
	public void setDateProc(DateProcess dateProc) {
		this.dateProc = dateProc;
	}
	public void setAbDAO(AddrBookDAO abDAO) {
		this.abDAO = abDAO;
	}
	public void setByear(int byear) {
		this.byear = byear;
	}
	public void setBmonth(int bmonth) {
		this.bmonth = bmonth;
	}
	public void setBday(int bday) {
		this.bday = bday;
	}
	@Override
	public void prepare() throws Exception {
		abvo = new AddrBookVO();
	}
	@Override
	public Object getModel() {
		return abvo;
	}
	
	public String insertAB(){
		String result = "";
		abvo.setBirth(dateProc.valueToDate(byear, bmonth, bday));
		try {			
			//System.out.println(abvo.toString());
			abDAO.insertAddrBook(abvo);
			result = "success";
		} catch (Exception e) {
			System.out.println("AddrInputAction.insertAB():"+e.toString());
			result = "error";
		}		
		return result;		
	}
	
	public String updateAB(){
		String result = "";		
		
		try {
			abDAO.updateAddrBook(abvo);
			result = "success";
		} catch (Exception e) {
			System.out.println("AddrInputAction.updateAB():"+e.toString());
			result = "error";
		}		
		return result;		
	}
}
